<template>
  <div class="wrapper">
    <div class="header" @click="handleBackPressed">
      <img src="@/assets/images/home.png" class="back" alt="header" />
      <div class="title">高考填报指南</div>
    </div>
    <div class="main">
      <div class="tabs">
        <div
          :class="['tab-item', activeTab == item.id ? 'active' : '']"
          v-for="item in tabs"
          :key="item.id"
          @click="handleTabClick(item)"
        >
          {{ item.name }}
        </div>
      </div>
      <div class="title-box">
        <Title :title="tabs[activeTab - 1].name" />
      </div>
      <div class="content">
        <keep-alive>
          <component :is="currentComponent" />
        </keep-alive>
      </div>
    </div>
  </div>
</template>
<script setup>
import { ref, onMounted, shallowRef, markRaw } from 'vue';
import { useRouter } from 'vue-router';
import { onBackPressed } from '@/utils/androidFn.js';
import CommonSense from './components/CommonSense.vue';
import Setting from './components/Setting.vue';
import Skill from './components/Skill.vue';
import Title from './components/Title.vue';
const tabs = shallowRef([
  {
    id: 1,
    name: '志愿常识',
    component: markRaw(CommonSense),
  },
  {
    id: 2,
    name: '志愿设置',
    component: markRaw(Setting),
  },
  {
    id: 3,
    name: '填报技巧',
    component: markRaw(Skill),
  },
]);

const activeTab = ref(1);
const currentComponent = ref(tabs.value[0].component);
const handleTabClick = (item) => {
  activeTab.value = item.id;
  currentComponent.value = item.component;
};

const router = useRouter();
const handleBackPressed = () => {
  onBackPressed(router);
};

onMounted(() => {});
</script>

<style scoped lang="scss">
.wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  // background: #e7f6fd;
  background: url('@/assets/images/homeBg.png') no-repeat center center;
  background-size: 100% 100%;
  padding: 0 32px;
  .header {
    display: flex;
    justify-content: center;
    font-size: 38px;
    color: #333;
    font-weight: bold;
    text-align: center;
    padding: 30px 0 18px 0;
    box-sizing: border-box;
    .back {
      position: absolute;
      left: 30px;
      width: 48px;
      height: 48px;
    }
  }
  .main {
    box-sizing: border-box;
    padding: 18px 32px 32px 32px;
    background-color: #fff;
    border-radius: 0 0 8px 8px;
    flex: 1;
    .tabs {
      display: flex;
      gap: 24px;
      justify-content: center;
      position: sticky;
      top: 0;
      z-index: 10;
      background-color: #fff;
      border-radius: 8px 8px 0 0;
      .tab-item {
        text-align: center;
        padding: 8px 94px;
        color: $primary-color;
        font-size: 30px;
        font-weight: bold;
        border-radius: 8px 8px 0 0;
        background-color: #d6e7ff;
        &.active {
          color: #fff;
          background-color: $primary-color;
        }
      }
    }
    .title-box {
      padding-top: 24px;
    }
  }
}
</style>
